<?php
/**
 * 关于页面控制器
 * @author caoge
 * @version 2012-8-1
 */
class AboutAction extends BaseAction{
	public function __construct(){
		parent::__construct();
		$this->assign('hover','about');
	}
	
	/**
	 * 关于页面显示
	 * 
	 * @author caoge
	 * @version 2012-8-1
	 */
	public function index(){
		$About = D(About);
		$aboutInfo = $About->find();
		
		//留言列表
		$Guestbook = D(Guestbook);
		import("ORG.Util.Page");
		$where = 'del_flag=0 AND status=1';
		$count = $Guestbook->where($where)->count();
		$p = new Page($count,20);
		$messageList = $Guestbook->relation(true)->where($where)->limit($p->firstRow.','.$p->listRows)->order('create_time desc')->select();
		
		$this->assign('headTitle','关于');
		$this->assign('aboutInfo',$aboutInfo);
		$this->assign('messageList',$messageList);
		$this->display();
	}
	
	/**
	 * 游客留言
	 *
	 * @author caoge
	 * @version 2012-8-1
	 */
	public function leaveWord(){
		$author = $this->_post('author','strip_tags','');
		$content = $this->_post('content','strip_tags','');
		$verifyCode = $this->_post('verifyCode');
		$jumpUrl = __APP__.'/About/index/';
		//检查验证码
		if(md5($verifyCode) != $_SESSION['verify']){
			$this->error('验证码错误',$jumpUrl);
		}elseif ($author == ''){
			$this->error('昵称不能为空',$jumpUrl);
		}elseif ($content == ''){
			$this->error('评论内容不能为空',$jumpUrl);
		}
		$Guestbook = D(Guestbook);
		$data = array(
				'author'=>$author,
				'content'=>$content,
				'create_time'=>date('Y-m-d H:i:s',time()),
				'status'=>1, //先不用审核功能
				'author_IP'=>get_client_ip()
		);
		$status = $Guestbook->data($data)->add();
		if ($status){
			$this->success('留言成功',$jumpUrl);
		}else {
			$this->success('留言失败',$jumpUrl);
		}
	}
}